package com.example.crazy3d;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;

import com.orhanobut.logger.Logger;

import java.util.Vector;

public class InformationDictatorship {
    public HandlerThread InformationDictatorship_HandlerThread;
    public Handler InformationDictatorship_Handler;
    public ProcessInformation ProcessInformationThread;
    public InformationDictatorship(MainActivity PrintScavengers_MainActivity) {
        InformationDictatorship_HandlerThread = new HandlerThread("InformationDictatorship_HandlerThread");
        ProcessInformationThread = new ProcessInformation(PrintScavengers_MainActivity.MainHandler);
        InformationDictatorship_HandlerThread.start();
        InformationDictatorship_Handler = new Handler(InformationDictatorship_HandlerThread.getLooper()) {
            @Override
            public void handleMessage (Message msg) {
                switch (msg.what) {
                    case StatusUtils.PrintingPipeline:
                        if ((msg.arg1 == StatusUtils.InformationDictatorship) && (msg.arg2 == StatusUtils.PrintScavengers)) {
                            ProcessInformationThread.PushCommand(msg.obj);
                        }
                        break;
                    default:
                        break;
                }
            }
        };
        new Thread(ProcessInformationThread,"ProcessInformation").start();
    }
    public void SendMessage(int des, Message msg) {
        if (des == StatusUtils.InformationDictatorship && msg.what == StatusUtils.PrintingPipeline) {
//            InformationDictatorship_Handler.sendMessage(msg);
            ProcessInformationThread.PushCommand(msg.obj);
        }
    }
    static class ProcessInformation implements Runnable {
        final Handler ProcessInformationHandler;
        final Vector<Object> CmdVector;
        public ProcessInformation(Handler handler) {
            ProcessInformationHandler = handler;
            CmdVector = new Vector<>();
        }
        public void PushCommand(Object cmd) {
            CmdVector.add(cmd);
        }
        @Override
        public void run() {
            while (true) {
                if (CmdVector.size() != 0) {
                    Logger.d(CmdVector.firstElement());
                    CmdVector.removeElementAt(0);
                }
            }



        }
    }
}
